package com.auxgroup.hr.front.dao.repository;

import com.auxgroup.hr.front.dao.domain.PsCLeaveTbl;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface PsCLeaveTblRepository extends JpaRepository<PsCLeaveTbl, String> {


    /**
     * 获取审批通过的产检天数总计
     *
     * @param cPregnantTime 怀孕时长
     * @param startDate     开始时间
     * @param emplid        员工工号
     * @return
     */
    @Query(value = "SELECT SUM(C_LEAVE_DAYS) " +
            " FROM ps_c_leave_tbl " +
            " WHERE emplid=:emplid" +
            " AND to_char(START_DATE,'yyyy-MM')=to_char(:startDate,'yyyy-MM') " +
            " AND C_LEAVE_TYPE='L200' " +
            " AND C_PREGNANT_TIME=:cPregnantTime" +
            " AND C_LEAVE_REQ_TYPE='A'", nativeQuery = true)
    List countAppliedPregnantDays(@Param("cPregnantTime") String cPregnantTime, @Param("startDate") Date startDate, @Param("emplid") String emplid);


}
